//
//  MapCell.m
//  WGFGlobalHouses
//
//  Created by welldone on 15/5/8.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "MapCell.h"
#import <MapKit/MapKit.h>
#import "Tools.h"


@interface MapCell ()

@property (weak, nonatomic) IBOutlet UILabel *titleLab;
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property (nonatomic,weak) CLLocationManager *locationManager;
@property (nonatomic,assign) CLLocationCoordinate2D  curLocation;


@end

@implementation MapCell



+(instancetype) cellWithTableView:(UITableView *)tableview;
{
    static NSString *ID = @"MapCell";
    MapCell *cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if (cell == nil)
    {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"MapCell" owner:nil options:nil]lastObject];
        [cell.cellBtn setBackgroundImage:[Tools getImgByColor:cell.cellBtn.backgroundColor] forState:UIControlStateNormal];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        cell.mapView.mapType = MKMapTypeStandard;
        cell.mapView.zoomEnabled=false;
        cell.mapView.showsUserLocation=YES;
        [cell.mapView setUserInteractionEnabled:false];
    }
    
    return cell;
}



+(CGFloat)getHight:(HourseMapCellData *)data withTableView:(UITableView *)tableView{
    
    
    static MapCell *cell = nil;
    
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
    
        cell = [MapCell cellWithTableView:tableView];
    });
    
    [cell setData:data];
    
    CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    
    return  height+1;
    
}




-(void)setData:(HourseMapCellData*)data{

    MKCoordinateRegion region;
    region.center.latitude = data.coordinate.latitude;
    region.center.longitude = data.coordinate.longitude;
    region.span.latitudeDelta = 0.1;
    region.span.longitudeDelta = 0.1;
    region = [self.mapView regionThatFits:region];
    [self.mapView setRegion:region animated:TRUE];

    
    [self.mapView addAnnotation:data];
//    [self.mapView selectAnnotation:data animated:YES];
    [self.mapView setCenterCoordinate:data.coordinate animated:YES];
    
}







@end
